import 'package:ca_dsp_pro/src/tool/assets.dart';
import 'package:flutter_kit_dsp/flutter_kit_dsp.dart';
import 'package:flutter_kit_plus/flutter_kit.dart';

class DelayItem extends StatefulWidget {
  String name;
  double max;
  double min;
  double value;
  String phase;
  String unit;
  void Function(double, bool)? onChanged;
  void Function()? onPhaseChanged;
  void Function()? onUnitChanged;
  DelayItem(
      {super.key,
      required this.name,
      required this.max,
      required this.min,
      required this.value,
      required this.phase,
      required this.unit,
      required this.onChanged,
      required this.onPhaseChanged,
      required this.onUnitChanged});

  @override
  State<DelayItem> createState() => _DelayItemState();
}

class _DelayItemState extends State<DelayItem> {
  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(color: Color_bg_view2, borderRadius: BorderRadius.circular(0)),
      padding: const EdgeInsets.only(top: 5, left: 5, right: 5, bottom: 5),
      child: Column(spacing: 5, children: [
        Container(
          height: 20,
          child: Center(
            child: FittedBox(
              fit: BoxFit.scaleDown,
              child: Text(widget.name),
            ),
          ),
        ),
        Expanded(
          child: Container(
            color: Color_bar,
            child: kSlider(
              dirction: Axis.horizontal,
              value: widget.value,
              min: widget.min,
              max: widget.max,
              onChanged: (currentValue) => widget.onChanged?.call(currentValue, false),
              onChangedForSend: (currentValue) => widget.onChanged?.call(currentValue, true),
            ),
          ),
        ),
        Container(
          color: Color_border,
          height: 30,
          child: Center(
            child: Text('${widget.value}'),
          ),
        ),
        Container(
          color: Color_border,
          height: 30,
          child: Material(
            color: Colors.transparent,
            child: InkWell(child: Center(child: Text(widget.unit)), onTap: () => widget.onUnitChanged?.call()),
          ),
        ),
        Container(
          color: Color_border,
          height: 30,
          child: Material(
            color: Colors.transparent,
            child: InkWell(child: Center(child: Text(widget.phase)), onTap: () => widget.onPhaseChanged?.call()),
          ),
        ),
      ]),
    );
  }
}
